package com.xmy.study.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.study.entity.AuthAdminContent;
import com.xmy.study.entity.ChaPlan;
import com.xmy.study.entity.EduTask;
import com.xmy.study.entity.views.PassRade;
import com.xmy.study.entity.views.PlanShutNum;
import com.xmy.study.service.IChaPlanService;
import com.xmy.study.service.IEduTaskService;
import com.xmy.study.util.Code;
import com.xmy.study.util.DateUtil;
import com.xmy.study.util.PageResult;
import com.xmy.study.util.Result;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import scala.Int;

import java.time.LocalDate;
import java.util.*;

@RestController
@RequestMapping("/api/outside/chaPlan")
public class ChaPlanController {

    @Autowired
    @Lazy
    IChaPlanService iChaPlanService;

    @Autowired
    @Lazy
    IEduTaskService eduTaskService;

    @Autowired
    @Lazy
    IEduTaskService iEduTaskService;

    /**
     * 获取计划
     *
     * @param chaPlan
     * @return
     */
    @ApiOperation("获取计划")
    @GetMapping("getChaPlan")
    public ChaPlan getChaPlan(@RequestParam ChaPlan chaPlan) {
        QueryWrapper<ChaPlan> chaPlanQueryWrapper = new QueryWrapper<>();
        //chaPlanQueryWrapper.eq("student_grade_id", chaPlan.getStudentGradeId());
        chaPlanQueryWrapper.eq("student_id", chaPlan.getStudentId());
        chaPlanQueryWrapper.eq("school_id", chaPlan.getSchoolId());
        chaPlanQueryWrapper.eq("year_part", chaPlan.getYearPart());
        chaPlanQueryWrapper.eq("year_class_id", chaPlan.getYearClassId());
        chaPlanQueryWrapper.eq("quarter_num", chaPlan.getQuarterNum());
        chaPlanQueryWrapper.eq("lesson_num", chaPlan.getLessonNum());
        //chaPlanQueryWrapper.eq("school_date", chaPlan.getSchoolDate());
        chaPlanQueryWrapper.last("LIMIT 1");
        return iChaPlanService.getOne(chaPlanQueryWrapper);
    }

    /**
     * 未完成计划
     *
     * @param reMap
     * @return
     */
    @ApiOperation("未完成计划")
    @PostMapping("getChaPlanList")
    public List<ChaPlan> getChaPlanList(@RequestBody Map<String, Object> reMap) {
        String schoolDate = null;
        if (reMap.get("schoolDate") != null && !reMap.get("schoolDate").toString().isEmpty()) {
            schoolDate = reMap.get("schoolDate").toString();
        }
        String schoolId = null;
        if (reMap.get("schoolId") != null && !reMap.get("schoolId").toString().isEmpty()) {
            schoolId = reMap.get("schoolId").toString();
        }
        QueryWrapper<ChaPlan> chaPlanQueryWrapper = new QueryWrapper<>();
        chaPlanQueryWrapper.le("school_date", schoolDate);
        if (schoolId != null && !schoolId.isEmpty()) {
            chaPlanQueryWrapper.eq("school_id", schoolId);
        }
        String yearClassIdString = null;
        //年级
        if (reMap.get("yearClassId") != null && !reMap.get("yearClassId").toString().isEmpty()) {
            yearClassIdString = reMap.get("yearClassId").toString();
        }
        //学段
        if (reMap.get("gradeSection") != null && !reMap.get("gradeSection").toString().isEmpty()) {
            yearClassIdString = reMap.get("gradeSection").toString();
        }
        if (yearClassIdString != null) {
            chaPlanQueryWrapper.eq("year_class_id", yearClassIdString);
        }
        if (reMap.get("teacherId") != null && !reMap.get("teacherId").toString().isEmpty()) {
            chaPlanQueryWrapper.eq("teacher_id", reMap.get("teacherId"));
        }
        if (reMap.get("gradeId") != null && !reMap.get("gradeId").toString().isEmpty()) {
            chaPlanQueryWrapper.eq("grade_id", reMap.get("gradeId"));
        }
//        if (reMap.get("courseTypeId") != null && !reMap.get("courseTypeId").toString().isEmpty()) {
//            chaPlanQueryWrapper.eq("course_type_id", reMap.get("courseTypeId"));
//        }
        chaPlanQueryWrapper.gt("lowest_shutnum - right_num - amend_num", 0);
        return iChaPlanService.list(chaPlanQueryWrapper);
    }

    /**
     * 已完成计划
     *
     * @param reMap
     * @return
     */
    @ApiOperation("已完成计划")
    @PostMapping("getChaPlanListYes")
    public List<ChaPlan> getChaPlanListYes(@RequestBody Map<String, Object> reMap) {
        String schoolDate = null;
        if (reMap.get("schoolDate") != null && !reMap.get("schoolDate").toString().isEmpty()) {
            schoolDate = reMap.get("schoolDate").toString();
        }
        String schoolId = null;
        if (reMap.get("schoolId") != null && !reMap.get("schoolId").toString().isEmpty()) {
            schoolId = reMap.get("schoolId").toString();
        }
        QueryWrapper<ChaPlan> chaPlanQueryWrapper = new QueryWrapper<>();
        chaPlanQueryWrapper.le("school_date", schoolDate);
        if (schoolId != null && !schoolId.isEmpty()) {
            chaPlanQueryWrapper.eq("school_id", schoolId);
        }
        String yearClassIdString = null;
        //年级
        if (reMap.get("yearClassId") != null && !reMap.get("yearClassId").toString().isEmpty()) {
            yearClassIdString = reMap.get("yearClassId").toString();
        }
        //学段
        if (reMap.get("gradeSection") != null && !reMap.get("gradeSection").toString().isEmpty()) {
            yearClassIdString = reMap.get("gradeSection").toString();
        }
        if (yearClassIdString != null) {
            chaPlanQueryWrapper.eq("year_class_id", yearClassIdString);
        }
        if (reMap.get("teacherId") != null && !reMap.get("teacherId").toString().isEmpty()) {
            chaPlanQueryWrapper.eq("teacher_id", reMap.get("teacherId"));
        }
        if (reMap.get("gradeId") != null && !reMap.get("gradeId").toString().isEmpty()) {
            chaPlanQueryWrapper.eq("grade_id", reMap.get("gradeId"));
        }
//        if (reMap.get("courseTypeId") != null && !reMap.get("courseTypeId").toString().isEmpty()) {
//            chaPlanQueryWrapper.eq("course_type_id", reMap.get("courseTypeId"));
//        }
        chaPlanQueryWrapper.eq("lowest_shutnum - right_num - amend_num", 0);
        return iChaPlanService.list(chaPlanQueryWrapper);
    }


    /**
     * 保存计划
     *
     * @param chaPlan
     * @return
     */
    @ApiOperation("保存计划")
    @PostMapping("saveChaPlan")
    public boolean saveChaPlan(@RequestBody ChaPlan chaPlan) {
        QueryWrapper<ChaPlan> chaPlanQueryWrapper = new QueryWrapper<>();
        //chaPlanQueryWrapper.eq("student_grade_id", chaPlan.getStudentGradeId());
        chaPlanQueryWrapper.eq("student_id", chaPlan.getStudentId());
        chaPlanQueryWrapper.eq("school_id", chaPlan.getSchoolId());
        chaPlanQueryWrapper.eq("year_part", chaPlan.getYearPart());
        chaPlanQueryWrapper.eq("year_class_id", chaPlan.getYearClassId());
        chaPlanQueryWrapper.eq("quarter_num", chaPlan.getQuarterNum());
        //chaPlanQueryWrapper.eq("school_date", chaPlan.getSchoolDate());
        chaPlanQueryWrapper.eq("teacher_id", chaPlan.getTeacherId());
        chaPlanQueryWrapper.eq("grade_id", chaPlan.getGradeId());
        chaPlanQueryWrapper.last("LIMIT 1");
        ChaPlan chaPlanServiceOne = iChaPlanService.getOne(chaPlanQueryWrapper);
        QueryWrapper<EduTask> eduTaskQueryWrapper = new QueryWrapper<>();
        eduTaskQueryWrapper.eq("year_part", chaPlan.getYearPart());
        eduTaskQueryWrapper.eq("year_class_id", chaPlan.getYearClassId());
        eduTaskQueryWrapper.eq("quarter_num", chaPlan.getQuarterNum());
        Calendar calendar = Calendar.getInstance();
        //String[] date = chaPlan.getSchoolDate().toString().split("-");
        String[] date = new String[1];
        calendar.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
        int monthPart = calendar.get(calendar.MONTH);//当前月份
        int yearPart = calendar.get(calendar.YEAR);//当前年份
        int todayPart = calendar.get(calendar.DAY_OF_MONTH);//当前天数
        int week = calendar.get(calendar.DAY_OF_WEEK);
        if (week == 1) {
            calendar.set(yearPart, monthPart, (todayPart - 6));
        } else {
            calendar.set(yearPart, monthPart, (todayPart - (week - 2)));
        }
        int todayPartStart = calendar.get(calendar.DAY_OF_MONTH);//开始天数
        int monthPartStart = calendar.get(calendar.MONTH) + 1;//开始月份
        int yearPartStart = calendar.get(calendar.YEAR);//开始年份
        String oenDate = yearPartStart + "-" + monthPartStart + "-" + todayPartStart + " 00:00:00";
        if (week == 1) {
            calendar.set(yearPart, monthPart, todayPart);
        } else {
            calendar.set(yearPart, monthPart, (todayPart + (7 - week) + 1));
        }
        int todayPartEnd = calendar.get(calendar.DAY_OF_MONTH);//结束天数
        int monthPartEnd = calendar.get(calendar.MONTH) + 1;//结束月份
        int yearPartEnd = calendar.get(calendar.YEAR);//结束年份
        eduTaskQueryWrapper.between("task_date", oenDate, yearPartEnd + "-" + monthPartEnd + "-" + todayPartEnd + " 23:59:59");
        eduTaskQueryWrapper.last("LIMIT 1");
        EduTask eduTaskServiceOne = eduTaskService.getOne(eduTaskQueryWrapper);
        if (eduTaskServiceOne != null) {
            chaPlan.setLessonNum(eduTaskServiceOne.getTaskCourseNum());
            //chaPlan.setEduTaskId(eduTaskServiceOne.getId());
            chaPlan.setLowestShutnum(eduTaskServiceOne.getLowestShutnum());
            System.out.println("没有数据？");
        }
        if (chaPlanServiceOne != null) {
            chaPlan.setId(chaPlanServiceOne.getId());
            return iChaPlanService.updateById(chaPlan);
        }
        return iChaPlanService.save(chaPlan);
    }

    @ApiOperation("通关率-查询期间为当前周一至周日")
    @PostMapping("getClearanceRateChaPlan")
    public ChaPlan getClearanceRateChaPlan(@RequestBody PlanShutNum planShutNum) {
        ChaPlan chaPlanReturn = new ChaPlan();
        //初始化
        chaPlanReturn.setLessonNum(0);//总人数
        chaPlanReturn.setAmendNum((float) 0);//修正题数
        chaPlanReturn.setRightNum((float) 0);//正确题数
        chaPlanReturn.setLowestShutnum((float) 0);//应通关
        chaPlanReturn.setYearClassId(0);//通关数
        chaPlanReturn.setQuarterNum(0);//未通关数
        chaPlanReturn.setYearPart(0);//总和是否正常为 0
        if (planShutNum.getStudentIdList() == null) {
            return chaPlanReturn;
        }
        Calendar calendar = Calendar.getInstance();
        if (planShutNum.getTaskDateStart() != null) {
            String schoolDate = planShutNum.getTaskDateStart();
            String[] date = schoolDate.split("-");
            calendar.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
        }
        int monthPart = calendar.get(calendar.MONTH);//当前月份
        int yearPart = calendar.get(calendar.YEAR);//当前年份
        int todayPart = calendar.get(calendar.DAY_OF_MONTH);//当前天数
        int week = calendar.get(calendar.DAY_OF_WEEK);
        if (week == 1) {
            calendar.set(yearPart, monthPart, (todayPart - 6));
        } else {
            calendar.set(yearPart, monthPart, (todayPart - (week - 2)));
        }
        int todayPartStart = calendar.get(calendar.DAY_OF_MONTH);//开始天数
        int monthPartStart = calendar.get(calendar.MONTH) + 1;//开始月份
        int yearPartStart = calendar.get(calendar.YEAR);//开始年份
        if (week == 1) {
            calendar.set(yearPart, monthPart, todayPart);
        } else {
            calendar.set(yearPart, monthPart, (todayPart + (7 - week) + 1));
        }
        int todayPartEnd = calendar.get(calendar.DAY_OF_MONTH);//结束天数
        int monthPartEnd = calendar.get(calendar.MONTH) + 1;//结束月份
        int yearPartEnd = calendar.get(calendar.YEAR);//结束年份
        QueryWrapper<ChaPlan> chaPlanQueryWrapper = new QueryWrapper<>();
        chaPlanQueryWrapper.in("c.student_id", planShutNum.getStudentIdList());
        chaPlanQueryWrapper.between("c.school_date", yearPartStart + "-" + monthPartStart + "-" + todayPartStart + " 00:00:00", yearPartEnd + "-" + monthPartEnd + "-" + todayPartEnd + " 23:59:59");
        List<ChaPlan> clearanceRateChaPlan = iChaPlanService.getClearanceRateChaPlan(chaPlanQueryWrapper);

        if (clearanceRateChaPlan != null && !clearanceRateChaPlan.isEmpty()) {
            chaPlanReturn.setLessonNum(clearanceRateChaPlan.size());
            for (ChaPlan chaPlan : clearanceRateChaPlan) {
//                chaPlanReturn.setAmendNum(chaPlanReturn.getAmendNum() + chaPlan.getAmendNum());
//                chaPlanReturn.setRightNum(chaPlanReturn.getRightNum() + chaPlan.getRightNum());
//                chaPlanReturn.setLowestShutnum(chaPlanReturn.getLowestShutnum() + chaPlan.getLowestShutnum());
                if (chaPlan.getLowestShutnum() - chaPlan.getRightNum() - chaPlan.getRightNum() <= 0) {
                    chaPlanReturn.setYearClassId(chaPlanReturn.getYearClassId() + 1);
                } else {
                    chaPlanReturn.setQuarterNum(chaPlanReturn.getQuarterNum() + 1);
                }
            }
            chaPlanReturn.setYearPart(chaPlanReturn.getLessonNum() - chaPlanReturn.getYearClassId() - chaPlanReturn.getQuarterNum());
            //安条件进行处理
//            chaPlanReturn.setAmendNum(chaPlanReturn.getQuarterNum());//末通关:应通关题数·正确题数-修正题数≠0
//            chaPlanReturn.setRightNum(chaPlanReturn.getYearClassId());//已通关:应通关题数-正确题数-修正题数=0
//            chaPlanReturn.setLowestShutnum(chaPlanReturn.getLessonNum());//总人数 应通关题数
        }
        return chaPlanReturn;
    }


    /**
     * 数学数据录入列表
     *
     * @return
     */
    @GetMapping("/getChaPanAddList")
    public Page<ChaPlan> getChaPanAddList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
            @RequestParam(value = "yearPart", required = false) String yearPart,
            @RequestParam(value = "quarterNum", required = false) String quarterNum,
            @RequestParam(value = "teacherId", required = false) String teacherId,
            @RequestParam(value = "gradeId", required = false) String gradeId,
            @RequestParam(value = "yearClassId", required = false) String yearClassId,
            @RequestParam(value = "gradeSection", required = false) String gradeSection,
            @RequestParam(value = "classTypeId", required = false) String classTypeId,
            @RequestParam(value = "lessonNum", required = false) String lessonNum,
            @RequestParam(value = "studentName", required = false) String studentName,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "subjectsId", required = false) String subjectsId,
            @RequestParam(value = "count", required = false) String count,
            @RequestParam(value = "categoryId") Integer categoryId) {
        Page<ChaPlan> page = new Page<>(pageNum, pageSize);
        iChaPlanService.getChaPanAddList(page, schoolIdStr, yearPart, quarterNum, teacherId, gradeId, yearClassId, gradeSection, classTypeId, lessonNum, status, studentName, subjectsId, count, categoryId);
        return page;
    }

    /**
     * 添加数据
     *
     * @param chaPlan
     * @return
     */
    @PostMapping("/addChaPlan")
    public boolean addChaPlan(@RequestBody ChaPlan chaPlan) {
        return iChaPlanService.addChaPlan(chaPlan);
    }

    @GetMapping("/getPassRadeList")
    public List<ChaPlan> getPassRadeList(@RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
                                         @RequestParam(value = "yearPart", required = false) String yearPart,
                                         @RequestParam(value = "quarterNum", required = false) String quarterNum,
                                         @RequestParam(value = "type", required = false) String type,
                                         @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
                                         @RequestParam(value = "lessonNum", required = false) String lessonNum,
                                         @RequestParam(value = "yearClassId", required = false) String yearClassId,
                                         @RequestParam(value = "classTypeId", required = false) String classTypeId,
                                         @RequestParam(value = "readingType", required = false) String readingType,
                                         @RequestParam(value = "readingStatusStr", required = false) String readingStatusStr,
                                         @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
                                         @RequestParam(value = "passDate", required = false) String passDate,
                                         @RequestParam(value = "passDateStart", required = false) String passDateStart,
                                         @RequestParam(value = "passDateEnd", required = false) String passDateEnd,
                                         @RequestParam(value = "subjectsId", required = false) String subjectsId,
                                         @RequestParam(value = "rightNumStartDate", required = false) String rightNumStartDate,
                                         @RequestParam(value = "rightNumEndDate", required = false) String rightNumEndDate,
                                         @RequestParam(value = "trackId", required = false) String trackId,
                                         @RequestParam(value = "isYearClass", required = false, defaultValue = "0") Integer isYearClass,
                                         @RequestParam(value = "radeType", required = false) String radeType,
                                         @RequestParam(value = "listState", required = false) String listState,
                                         @RequestParam(value = "teacherId", required = false) String teacherId,
                                         @RequestParam(value = "name", required = false) String name,
                                         @RequestParam(value = "classify", required = false) String classify,
                                         @RequestParam(value = "trackType", required = false) String trackType,
                                         @RequestParam(value = "teamId", required = false) String teamId,
                                         @RequestParam(value = "include", required = false) String include,
                                         @RequestParam(value = "inType", required = false) String inType,
                                         @RequestParam(value = "categoryId") Integer categoryId,
                                         @RequestParam(value = "isAchieve") String isAchieve, // 0通关率、录入、完成率、正确率、修正率，1复刷完成率
                                         @RequestParam(value = "moldType") String moldType, // 1正常通关率、2到勤通关率
                                         @RequestParam(value = "courseSchedulingDetailName") String courseSchedulingDetailName,
                                         @RequestParam(value = "examSchedulingtType") String examSchedulingtType,   // 0全部 1已过刷题排班时间 2未到刷题排班时间AuthAdminContent authAdminContent
                                         @RequestParam(value = "leadSchoolIds",required = false) String leadSchoolIds,
                                         @RequestParam(value = "leadSubjectsIds",required = false) String leadSubjectsIds,
                                         @RequestParam(value = "leadYearClassIds",required = false) String leadYearClassIds,
                                         @RequestParam(value = "leadTeacherId",required = false) Long leadTeacherId,
                                         @RequestParam(value = "isIncludeFirstCourse",required = false) Integer isIncludeFirstCourse
    ) {
        return iChaPlanService.getPassRadeList(yearPart, quarterNum, schoolIdStr, yearClassId, type, lessonNumStart, lessonNum, classTypeId, readingType, readingStatusStr,
                isBeforQuarter, passDate, passDateStart, passDateEnd, subjectsId, rightNumStartDate, rightNumEndDate, trackId, isYearClass, radeType, listState, teacherId,
                name, classify, trackType, teamId, include, inType, categoryId, isAchieve, moldType, courseSchedulingDetailName,examSchedulingtType,
                leadSchoolIds, leadSubjectsIds, leadYearClassIds, leadTeacherId,  isIncludeFirstCourse);

    }

    @GetMapping("/getPassRadeDetail")
    public Page<ChaPlan> getPassRadeDetail(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
            @RequestParam(value = "yearPart", required = false) String yearPart,
            @RequestParam(value = "quarterNum", required = false) String quarterNum,
            @RequestParam(value = "teacherId", required = false) String teacherId,
            @RequestParam(value = "type", required = false) String type,
            @RequestParam(value = "gradeId", required = false) String gradeId,
            @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
            @RequestParam(value = "lessonNum", required = false) String lessonNum,
            @RequestParam(value = "yearClassId", required = false) String yearClassId,
            @RequestParam(value = "classTypeId", required = false) String classTypeId,
            @RequestParam(value = "readingType", required = false) String readingType,
            @RequestParam(value = "readingStatusStr", required = false) String readingStatusStr,
            @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
            @RequestParam(value = "passType", required = false) String passType,
            @RequestParam(value = "courseVersionId", required = false) String courseVersionId,
            @RequestParam(value = "passDate", required = false) String passDate,
            @RequestParam(value = "passDateStart", required = false) String passDateStart,
            @RequestParam(value = "passDateEnd", required = false) String passDateEnd,
            @RequestParam(value = "subjectsId", required = false) String subjectsId,
            @RequestParam(value = "rightNumStartDate", required = false) String rightNumStartDate,
            @RequestParam(value = "rightNumEndDate", required = false) String rightNumEndDate,
            @RequestParam(value = "studentName", required = false) String studentName,
            @RequestParam(value = "radeType", required = false) String radeType,
            @RequestParam(value = "listState", required = false) String listState,
            @RequestParam(value = "classify", required = false) String classify,
            @RequestParam(value = "trackType", required = false) String trackType,
            @RequestParam(value = "teamId", required = false) String teamId,
            @RequestParam(value = "include", required = false) String include,
            @RequestParam(value = "inType", required = false) String inType,
            @RequestParam(value = "categoryId") Integer categoryId,
            @RequestParam(value = "courseSchedulingDetailName") String courseSchedulingDetailName,
            @RequestParam(value = "studentIdStr", required = false) String studentIdStr,
            @RequestParam(value = "moldType") String moldType, // 1正常通关率、2到勤通关率
            @RequestParam(value = "examSchedulingtType") String examSchedulingtType,   // 0全部 1已过刷题排班时间 2未到刷题排班时间
            @RequestParam(value = "leadSchoolIds",required = false) String leadSchoolIds,
            @RequestParam(value = "leadSubjectsIds",required = false) String leadSubjectsIds,
            @RequestParam(value = "leadYearClassIds",required = false) String leadYearClassIds,
            @RequestParam(value = "leadTeacherId",required = false) Long leadTeacherId,
            @RequestParam(value = "isIncludeFirstCourse",required = false) Integer isIncludeFirstCourse
    ) {
        if (StringUtils.isNotBlank(rightNumStartDate) && StringUtils.isNotBlank(rightNumEndDate)) {
            inType = "2";//为inner查找
        }
        Page<ChaPlan> page = new Page<>(pageNum, pageSize);
        iChaPlanService.getPassRadeDetail(page, yearPart, quarterNum, schoolIdStr, teacherId, yearClassId, type, gradeId, lessonNumStart,
                lessonNum, classTypeId, readingType, readingStatusStr, isBeforQuarter, passType, courseVersionId, passDate, passDateStart,
                passDateEnd, subjectsId, rightNumStartDate, rightNumEndDate, studentName, radeType, listState, classify, trackType, teamId,
                include, inType, categoryId, courseSchedulingDetailName, studentIdStr, moldType, examSchedulingtType,
                leadSchoolIds, leadSubjectsIds, leadYearClassIds, leadTeacherId,isIncludeFirstCourse);

        return page;
    }

    @GetMapping("/getPassRadeDetailTotal")
    public ChaPlan getPassRadeDetailTotal(
            @RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
            @RequestParam(value = "yearPart", required = false) String yearPart,
            @RequestParam(value = "quarterNum", required = false) String quarterNum,
            @RequestParam(value = "teacherId", required = false) String teacherId,
            @RequestParam(value = "type", required = false) String type,
            @RequestParam(value = "gradeId", required = false) String gradeId,
            @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
            @RequestParam(value = "lessonNum", required = false) String lessonNum,
            @RequestParam(value = "yearClassId", required = false) String yearClassId,
            @RequestParam(value = "classTypeId", required = false) String classTypeId,
            @RequestParam(value = "readingType", required = false) String readingType,
            @RequestParam(value = "readingStatusStr", required = false) String readingStatusStr,
            @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
            @RequestParam(value = "passType", required = false) String passType,
            @RequestParam(value = "courseVersionId", required = false) String courseVersionId,
            @RequestParam(value = "passDate", required = false) String passDate,
            @RequestParam(value = "passDateStart", required = false) String passDateStart,
            @RequestParam(value = "passDateEnd", required = false) String passDateEnd,
            @RequestParam(value = "subjectsId", required = false) String subjectsId,
            @RequestParam(value = "rightNumStartDate", required = false) String rightNumStartDate,
            @RequestParam(value = "rightNumEndDate", required = false) String rightNumEndDate,
            @RequestParam(value = "studentName", required = false) String studentName,
            @RequestParam(value = "radeType", required = false) String radeType,
            @RequestParam(value = "include", required = false) String include,
            @RequestParam(value = "inType", required = false) String inType,
            @RequestParam(value = "categoryId") Integer categoryId
    ) {
        return iChaPlanService.getPassRadeDetailTotal(yearPart, quarterNum, schoolIdStr, teacherId, yearClassId, type, gradeId, lessonNumStart, lessonNum, classTypeId, readingType, readingStatusStr, isBeforQuarter, passType, courseVersionId, passDate, passDateStart, passDateEnd, subjectsId, rightNumStartDate, rightNumEndDate, studentName, radeType, include, inType, categoryId);
    }


    /**
     * 后台签到查看用
     *
     * @param yearPart
     * @param quarterNum
     * @param studentId
     * @param subjectsId
     * @return
     */
    @GetMapping("/getPassRadeDetailForStudentId")
    public List<ChaPlan> getPassRadeDetailForStudentId(
            @RequestParam(value = "yearPart", required = false) String yearPart,
            @RequestParam(value = "quarterNum", required = false) String quarterNum,
            @RequestParam(value = "studentId", required = false) String studentId,
            @RequestParam(value = "subjectsId", required = false) String subjectsId,
            @RequestParam(value = "categoryId", required = false, defaultValue = "1") Integer categoryId,
            @RequestParam(value = "yetLessonNumStr", required = false) String yetLessonNumStr
    ) {
        List<ChaPlan> chaPlanList = iChaPlanService.getPassRadeDetailForStudentId(yearPart, quarterNum, studentId, subjectsId, categoryId, yetLessonNumStr);
        return chaPlanList;
    }

//    @PostMapping("/getPassRadeListAdmin")
//    public List<ChaPlan> getPassRadeListAdmin(@RequestBody PassRade passRade) {
//        String schoolIdStr = passRade.getSchoolIdStr();
//        String yearPart = passRade.getYearPart();
//        String quarterNum = passRade.getQuarterNum();
//        String type = passRade.getType();
//        String lessonNumStart = passRade.getLessonNumStart();
//        String lessonNum = passRade.getLessonNum();
//        String yearClassId = passRade.getYearClassId();
//        String classTypeId = passRade.getClassTypeId();
//        String readingType = passRade.getReadingType();
//        String readingStatusStr = passRade.getReadingStatusStr();
//        String isBeforQuarter = passRade.getIsBeforQuarter();
//        String passDate = passRade.getPassDate();
//        String passDateStart = passRade.getPassDateStart();
//        String passDateEnd = passRade.getPassDateEnd();
//        String subjectsId = passRade.getSubjectsId();
//        String rightNumStartDate = passRade.getRightNumStartDate();
//        String rightNumEndDate = passRade.getRightNumEndDate();
//        String trackId = passRade.getTrackId();
//        int isYearClass = passRade.getIsYearClass() == null ? 0 : passRade.getIsYearClass();
//        String radeType = passRade.getRadeType();
//        String listState = passRade.getListState();
//        String teacherId = passRade.getTeacherId();
//        String name = passRade.getName();
//        String include = passRade.getInclude();
//        String inType = passRade.getInType();
//        Integer categoryId = 1;
//        return iChaPlanService.getPassRadeList(yearPart, quarterNum, schoolIdStr, yearClassId, type, lessonNumStart, lessonNum, classTypeId, readingType, readingStatusStr, isBeforQuarter, passDate, passDateStart, passDateEnd, subjectsId, rightNumStartDate, rightNumEndDate, trackId, isYearClass, radeType, listState, teacherId, name, null, null, null, include, inType, categoryId, "0", "1");
//    }

    /**
     * 需订购
     *
     * @return
     */
    @GetMapping("/getNeedOrder")
    public Map<String, Object> getNeedOrder(@RequestParam("pageNum") Integer pageNum,
                                            @RequestParam("pageSize") Integer pageSize,
                                            @RequestParam("yearPart") Integer yearPart,
                                            @RequestParam("quarterNum") Integer quarterNum,
                                            @RequestParam("schoolId") Long schoolId,
                                            @RequestParam("lessonType") Integer lessonType,
                                            @RequestParam("subjectsId") Long subjectsId,
                                            @RequestParam(value = "yearClassId", required = false) Integer yearClassId,
                                            @RequestParam(value = "classTypeId", required = false) Long classTypeId,
                                            @RequestParam(value = "goodsTypeId", required = false) Long goodsTypeId,
                                            @RequestParam(value = "categoryId", defaultValue = "1", required = false) Integer categoryId) {
        Page<ChaPlan> iPage = new Page<>(pageNum, pageSize);

        Long courseVersionId = 1676874588501311488L;
        Integer startLessonNum = 1;
        Integer endLessonNum = 1;

        //System.out.println("进入getNeedOrder方法");

        //当前到了第几课次
        EduTask eduTaskNow = iEduTaskService.getTaskOneNow(yearPart.toString(), quarterNum.toString(), courseVersionId, subjectsId.toString(), categoryId);
        if (eduTaskNow == null) {
            //不存在就获取最大的课次
            eduTaskNow = iEduTaskService.getTaskOneBackTaskNum(yearPart.toString(), quarterNum.toString(), courseVersionId, subjectsId.toString(), categoryId);
        }
        if (eduTaskNow != null) {
            endLessonNum = eduTaskNow.getTaskCourseNum();
        }

        List<ChaPlan> chaPlanList = iChaPlanService.getNeedOrder(yearPart, quarterNum, schoolId, yearClassId, classTypeId, subjectsId, lessonType, goodsTypeId, startLessonNum, endLessonNum, categoryId);
        //System.out.println("进入chaPlanList");
        iChaPlanService.getNeedOrderForGroup(iPage, yearPart, quarterNum, schoolId, yearClassId, classTypeId, subjectsId, lessonType, goodsTypeId, startLessonNum, endLessonNum, categoryId);
        //System.out.println("进入getNeedOrderForGroup");
        Map<String, Object> map = new HashMap<>();
        map.put("list", chaPlanList);
        map.put("maxLessonNum", endLessonNum);
        map.put("classTypeList", new PageResult(iPage.getRecords(), iPage.getTotal(), iPage.getPages()));
        return map;
    }

    @PostMapping("/getChaPlanLessonNumString")
    public String getChaPlanLessonNumString(@RequestBody ChaPlan chaPlan) {
        return iChaPlanService.getChaPlanLessonNumString(chaPlan);
    }

    /**
     * 获取荣誉列表
     */
    @GetMapping("/getHonorList")
    public List<ChaPlan> getHonorList(@RequestParam(value = "yearPart", required = false) String yearPart,
                                      @RequestParam(value = "quarterNum", required = false) String quarterNum,
                                      @RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
                                      @RequestParam(value = "yearClassIdStr", required = false) String yearClassIdStr,
                                      @RequestParam(value = "type", required = false) String type,
                                      @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
                                      @RequestParam(value = "lessonNumEnd", required = false) String lessonNumEnd,
                                      @RequestParam(value = "classTypeId", required = false) String classTypeId,
                                      @RequestParam(value = "readingType", required = false) String readingType,
                                      @RequestParam(value = "subjectsId", required = false) String subjectsId,
                                      @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
                                      @RequestParam(value = "trackId", required = false) String trackId,
                                      @RequestParam(value = "teacherId", required = false) String teacherId,
                                      @RequestParam(value = "name", required = false) String name,
                                      @RequestParam(value = "include", required = false) String include,
                                      @RequestParam(value = "taskCategoryId", required = false) Integer taskCategoryId,
                                      @RequestParam(value = "classify", required = false) String classify,
                                      @RequestParam(value = "trackType", required = false) String trackType,
                                      @RequestParam(value = "teamId", required = false) String teamId,
                                      @RequestParam(value = "startDate", required = false) String startDate,
                                      @RequestParam(value = "endDate", required = false) String endDate
    ) {
        return iChaPlanService.getHonorList(yearPart, quarterNum, schoolIdStr, yearClassIdStr, type, lessonNumStart, lessonNumEnd, classTypeId, readingType, subjectsId, isBeforQuarter, trackId, teacherId, name, include, taskCategoryId, classify, trackType, teamId, startDate, endDate);
    }

    /**
     * 获取荣誉详情
     */
    @GetMapping("/getHonorDetails")
    public Page<ChaPlan> getHonorDetails(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(value = "yearPart", required = false) String yearPart,
                                         @RequestParam(value = "quarterNum", required = false) String quarterNum,
                                         @RequestParam(value = "schoolIdStr", required = false) String schoolIdStr,
                                         @RequestParam(value = "yearClassIdStr", required = false) String yearClassIdStr,
                                         @RequestParam(value = "type", required = false) String type,
                                         @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
                                         @RequestParam(value = "lessonNumEnd", required = false) String lessonNumEnd,
                                         @RequestParam(value = "classTypeId", required = false) String classTypeId,
                                         @RequestParam(value = "readingType", required = false) String readingType,
                                         @RequestParam(value = "subjectsId", required = false) String subjectsId,
                                         @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
                                         @RequestParam(value = "trackId", required = false) String trackId,
                                         @RequestParam(value = "teacherId", required = false) String teacherId,
                                         @RequestParam(value = "name", required = false) String name,
                                         @RequestParam(value = "include", required = false) String include,
                                         @RequestParam(value = "taskCategoryId", required = false) Integer taskCategoryId,
                                         @RequestParam(value = "passType", required = false) String passType,
                                         @RequestParam(value = "classify", required = false) String classify,
                                         @RequestParam(value = "trackType", required = false) String trackType,
                                         @RequestParam(value = "teamId", required = false) String teamId,
                                         @RequestParam(value = "gradeId", required = false) String gradeId,
                                         @RequestParam(value = "startDate", required = false) String startDate,
                                         @RequestParam(value = "endDate", required = false) String endDate
    ) {
        Page<ChaPlan> page = new Page<>(pageNum, pageSize);
        iChaPlanService.getHonorDetails(page, yearPart, quarterNum, schoolIdStr, yearClassIdStr, type, lessonNumStart, lessonNumEnd, classTypeId, readingType, subjectsId, isBeforQuarter, trackId, teacherId, name, include, taskCategoryId, passType, classify, trackType, teamId, gradeId, startDate, endDate);
        return page;
    }


    /**
     * 数学积分列表
     */
    @GetMapping("/getPassRadeIntegralList")
    public List<ChaPlan> getPassRadeIntegralList(
            @RequestParam(value = "yearPart", required = false) String yearPart,
            @RequestParam(value = "quarterNum", required = false) String quarterNum,
            @RequestParam(value = "schoolId", required = false) String schoolId,
            @RequestParam(value = "teacherId", required = false) String teacherId,
            @RequestParam(value = "yearClassId", required = false) String yearClassId,
            @RequestParam(value = "subjectsId", required = false, defaultValue = "2") Long subjectsId,
            @RequestParam(value = "classTypeId", required = false) String classTypeId,
            @RequestParam(value = "readingType", required = false) String readingType,
            @RequestParam(value = "courseVersionId", required = false) Long courseVersionId,
            @RequestParam(value = "include", required = false) String include,
            @RequestParam(value = "taskCategoryId", required = false) String taskCategoryId,
            @RequestParam(value = "classify", required = false) String classify,
            @RequestParam(value = "trackType", required = false) String trackType,
            @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
            @RequestParam(value = "teamId", required = false) String teamId,
            @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
            @RequestParam(value = "lessonNumEnd", required = false) String lessonNumEnd,
            @RequestParam(value = "startDate", required = false) String startDate,
            @RequestParam(value = "endDate", required = false) String endDate,
            @RequestParam(value = "type", required = false) String type,
            @RequestParam(value = "inType", required = false) String inType,// 1、全部，2已录
            @RequestParam(value = "moldType", required = false) String moldType,  // 1、正确率，2、通关率，3、费曼学习积分
            @RequestParam(value = "listState", required = false) String listState
    ) {
        return iChaPlanService.getPassRadeIntegralList(yearPart, quarterNum, schoolId, teacherId, yearClassId, subjectsId, classTypeId, readingType, courseVersionId, isBeforQuarter, include, taskCategoryId, classify, trackType, teamId, lessonNumStart, lessonNumEnd, startDate, endDate, type, inType, listState, moldType);
    }

    /**
     * 数学积分详情
     */
    @GetMapping("/getPassRadeIntegralDetail")
    public Page<ChaPlan> getPassRadeIntegralDetail(@RequestParam(value = "pageNum", defaultValue = "-1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "-1") Integer pageSize,
                                                   @RequestParam(value = "yearPart", required = false) String yearPart,
                                                   @RequestParam(value = "quarterNum", required = false) String quarterNum,
                                                   @RequestParam(value = "schoolId", required = false) String schoolId,
                                                   @RequestParam(value = "teacherId", required = false) String teacherId,
                                                   @RequestParam(value = "studentId", required = false) String studentId,
                                                   @RequestParam(value = "yearClassId", required = false) String yearClassId,
                                                   @RequestParam(value = "subjectsId", required = false, defaultValue = "2") Long subjectsId,
                                                   @RequestParam(value = "gradeId", required = false) String gradeId,
                                                   @RequestParam(value = "classTypeId", required = false) String classTypeId,
                                                   @RequestParam(value = "readingType", required = false) String readingType,
                                                   @RequestParam(value = "courseVersionId", required = false) Long courseVersionId,
                                                   @RequestParam(value = "studentName", required = false) String studentName,
                                                   @RequestParam(value = "include", required = false) String include,
                                                   @RequestParam(value = "taskCategoryId", required = false) String taskCategoryId,
                                                   @RequestParam(value = "classify", required = false) String classify,
                                                   @RequestParam(value = "trackType", required = false) String trackType,
                                                   @RequestParam(value = "isBeforQuarter", required = false) String isBeforQuarter,
                                                   @RequestParam(value = "teamId", required = false) String teamId,
                                                   @RequestParam(value = "lessonNumStart", required = false) String lessonNumStart,
                                                   @RequestParam(value = "lessonNumEnd", required = false) String lessonNumEnd,
                                                   @RequestParam(value = "startDate", required = false) String startDate,
                                                   @RequestParam(value = "endDate", required = false) String endDate,
                                                   @RequestParam(value = "type", required = false) String type,
                                                   @RequestParam(value = "inType", required = false) String inType,// 1、全部，2已录
                                                   @RequestParam(value = "moldType", required = false) String moldType,  // 1、正确率，2、通关率，3、费曼学习积分
                                                   @RequestParam(value = "listState", required = false) String listState
    ) {
        Page<ChaPlan> page = new Page<>(pageNum, pageSize);
        iChaPlanService.getPassRadeIntegralDetail(page, yearPart, quarterNum, schoolId, teacherId, studentId, yearClassId, subjectsId, gradeId, classTypeId, readingType, courseVersionId, isBeforQuarter, studentName, include, taskCategoryId, classify, trackType, teamId, lessonNumStart, lessonNumEnd, startDate, endDate, type, inType, moldType, listState);
        return page;
    }

    /**
     * 数学积分录入列表
     */
    @GetMapping("/getChaPanIntegralAddList")
    public Page<ChaPlan> getChaPanIntegralAddList(@RequestParam(value = "pageNum", defaultValue = "-1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "-1") Integer pageSize,
                                                  @RequestParam(value = "yearPart", required = false) String yearPart,
                                                  @RequestParam(value = "quarterNum", required = false) String quarterNum,
                                                  @RequestParam(value = "schoolId", required = false) String schoolId,
                                                  @RequestParam(value = "teacherId", required = false) String teacherId,
                                                  @RequestParam(value = "gradeId", required = false) String gradeId,
                                                  @RequestParam(value = "yearClassId", required = false) String yearClassId,
                                                  @RequestParam(value = "classTypeId", required = false) String classTypeId,
                                                  @RequestParam(value = "lessonNum", required = false) String lessonNum,
                                                  @RequestParam(value = "studentName", required = false) String studentName,
                                                  @RequestParam(value = "subjectsId", required = false) Long subjectsId,
                                                  @RequestParam(value = "courseVersionId", required = false) Long courseVersionId,
                                                  @RequestParam(value = "brushCount", required = false) String brushCount,
                                                  @RequestParam(value = "taskCategoryId", required = false) Integer taskCategoryId
    ) {
        Page<ChaPlan> page = new Page<>(pageNum, pageSize);
        iChaPlanService.getChaPanIntegralAddList(page, yearPart, quarterNum, schoolId, teacherId, gradeId, yearClassId, classTypeId, lessonNum, studentName, subjectsId, courseVersionId, brushCount, taskCategoryId);
        return page;
    }

    /**
     * 数学积分录入
     */
    @PostMapping("/addChaPanIntegra")
    public boolean addChaPanIntegra(@RequestBody ChaPlan chaPlan) {

        return iChaPlanService.addChaPanIntegra(chaPlan);
    }


    @GetMapping("/updatePassLesson")
    public Integer updatePassLesson(@RequestParam("yearPart") Integer yearPart,
                                   @RequestParam("quarterNum") Integer quarterNum
                                   ){
        iChaPlanService.updatePassLesson(yearPart,quarterNum);
        return 1;
    }
}
